import React, { useEffect, useState } from 'react'
import List from './List'
import SearchProject from './SearchProject'

const apiUrl = "http://localhost:3000"

export default function ProjectList() {

  const [users, setUsers] = useState(null);
  const [projects, setProjects] = useState(null);
  const [param, setParam] = useState({
    projectName: "",
    personId: null
  })

  useEffect(() => {
    // 请求负责人
    fetch(`${apiUrl}/users`).then(async (res) => {
      let users = await res.json();
      setUsers(users);
        // setUsers(users.filter((user)=> user.id === param.personId))
    })
    // 请求项目
    fetch(`${apiUrl}/projects`).then(async res => {
      setProjects(await res.json());
    })
  }, [param])

  
  return (
    <div>
      <SearchProject users={users} param={param} setParam={setParam} />
      <List projects={projects} param={param} users={users} />
    </div>
  )
}
